package com.ram.service.impl;

import com.ram.mapper.BuildingMapper;
import com.ram.pojo.Building;
import com.ram.pojo.BuildingDTO;
import com.ram.pojo.BuildingVO;
import com.ram.pojo.PageResult;
import com.ram.service.BuildingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class BuildingServiceImpl implements BuildingService {
    @Autowired
    private BuildingMapper buildingMapper;

    @Override
    public List<Building> list() {
        return buildingMapper.list();
    }

    @Override
    public Building getById(Integer id) {
        return buildingMapper.getById(id);
    }

    @Override
    public void add(Building building) {
        building.setCreateTime(LocalDateTime.now());
        building.setUpdateTime(LocalDateTime.now());
        buildingMapper.insert(building);
    }

    @Override
    public void update(Building building) {
        building.setUpdateTime(LocalDateTime.now());
        buildingMapper.update(building);
    }

    @Override
    public void deleteById(Integer id) {
        buildingMapper.deleteById(id);
    }

    @Override
    public PageResult<BuildingVO> pageQuery(BuildingDTO dto) {
        // PageHelper.startPage(dto.getPage(), dto.getPageSize());
        List<BuildingVO> list = buildingMapper.pageQuery(dto);
        long total = buildingMapper.countPageQuery(dto);
        return new PageResult<>(total, list);
    }
} 